package com.example.service.impl;

import com.example.pojo.Article;
import com.example.repository.ArticleRepository;
import com.example.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import static org.springframework.data.domain.Sort.by;

/**
 * @author mwx
 * @version 1.0
 * @date 2020/11/5 20:08
 */
@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleRepository articleRepository;



    @Override
    public Page<Article> getArticleList(int pageNum, int pageSize) {
        Sort.Order sort = new  Sort.Order(Sort.Direction.DESC, "id");
        Pageable pageable = PageRequest.of(pageNum, pageSize, Sort.by(sort));
        Page<Article> article = articleRepository.findAll(pageable);

        return article;
    }
    @Override
    public Article findUserById(long id) {
        return articleRepository.findById(id);
    }
}
